package fatworm.query;

import fatworm.storage.table.*;

public class ExtendPlan implements Plan {
	
	private Plan p;
	private String oldname, newname;
	private Schema sch = new Schema();
	
	public ExtendPlan(Plan p, String oldname, String newname) {
		this.p = p;
		this.oldname = oldname;
		this.newname = newname;
		sch.addAll(p.getSchema());
		sch.renameField(oldname, newname);
	}
	
	public Scan open() {
		return new ExtendScan(p.open(), oldname, newname);
	}
	
	public int blocksAccessed() {
		return p.blocksAccessed();
	}
	
	public int recordsOutput() {
		return p.recordsOutput();
	}
	
	public int distinctValues(String name) {
		if (newname.equals(name))
			return p.distinctValues(oldname);
		else
			return p.distinctValues(name);
	}
	
	public Schema getSchema() {
		return sch;
	}
	
}